package com.movitech.mobile.ddzy.modules.bpm.api;


import com.movitech.mobile.cz.base.common.license.LicenseUtil;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.ddzy.bpm.entity.SBpmCallback;
import com.movitech.mobile.ddzy.modules.bpm.bizservice.MbsBpmCallBackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * Mbs Bpm 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@RestController
@RequestMapping("/v1/public/bpm")
@Api(value = "MbsBpm接口", description = "MbsBpm接口")
public class MbsBpmCallBackController {

	@Autowired
    @Qualifier("mbsBpmCallBackService")
    private MbsBpmCallBackService mbsBpmCallBackService;

    @ApiOperation(
            value = "MbsBpm流程回调接口",
            notes = "MbsBpm流程回调接口",
            response = RestReturnResult.class
    )
    @RequestMapping(value = "/bpmCallBack", method = RequestMethod.POST)
    @ResponseBody
    public RestReturnResult<Object> mbsBpmCallBack(@RequestBody Map<String,String> requestBody) {
        LicenseUtil.INSTANCE.validate();
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL);
        try {
            SBpmCallback sBpmCallback = mbsBpmCallBackService.saveBpmCallBack(requestBody);
        	boolean isSuccess = mbsBpmCallBackService.mbsBpmCallBack(requestBody);
            SBpmCallback updateCallback = new SBpmCallback();
            updateCallback.setId(sBpmCallback.getId());
            updateCallback.setDelFlag(1);
            mbsBpmCallBackService.updateBpmCallBack(updateCallback);
        	hResult.setCode(isSuccess?CommonConstants.SUCCESS:CommonConstants.FAIL);
            hResult.setMsg("操作成功");
            hResult.setBussinessId("");
            hResult.setSystemCode("CGXT");
        } catch (Exception e) {
            e.printStackTrace();
            hResult.setMsg("操作失败");
            hResult.setBussinessId("");
            hResult.setSystemCode("CGXT");
            hResult = new RestReturnResult<Object>(CommonConstants.FAIL);
        }
        return hResult;
    }
}

